from django.db import models

"""
在线学习网项目模型
"""
from django.db import models

SEX_OPTIONS=((True,'男'),(False,'女'))
JURISDICTION_OPTIONS=((0,'普通用户'),(1,'个人会员'),(2,'企业会员'),(3,'公安部'),(888,'超级管理员'))
HANDLE_OPTIONS=((0,'未批复'),(1,'同意飞行'),(2,'拒绝飞行'))



# 1
class User(models.Model):
    """用户"""
    id = models.AutoField(primary_key=True, verbose_name='用户ID')
    username = models.CharField(unique=True, max_length=20, verbose_name='用户名')
    password = models.CharField(max_length=32, verbose_name='用户密码')
    jurisdiction = models.IntegerField(choices=JURISDICTION_OPTIONS,default=0, verbose_name='用户权限等级')
    is_realname= models.BooleanField(default=False, verbose_name='是否实名')

    real_name = models.CharField(max_length=50, null=True, verbose_name='用户真实姓名')
    age = models.IntegerField(null=True, verbose_name='年龄')
    sex = models.BooleanField(choices=SEX_OPTIONS, null=True, verbose_name='用户性别', )
    email = models.CharField(unique=True, max_length=255, verbose_name='用户邮箱',null=True)
    tel = models.CharField(unique=True, max_length=20, verbose_name='手机号', null=True)

    com_name = models.CharField(max_length=255, null=True, verbose_name='公司名称')
    com_address = models.CharField(max_length=255, null=True, verbose_name='公司地址')
    credit_code = models.CharField(max_length=255, null=True, verbose_name='公司统一信用代码')
    com_type = models.CharField(max_length=255, null=True, verbose_name='企业类型')
    legal_person = models.CharField(max_length=50, null=True, verbose_name='企业法人')
    reg_capital = models.CharField(max_length=50, null=True, verbose_name='注册资本')
    com_intro = models.CharField(max_length=255, null=True, verbose_name='公司介绍')

    dep_name = models.CharField(max_length=255, null=True, verbose_name='公安部门名称')
    county = models.CharField(max_length=50, null=True, verbose_name='公安部门所属区县')
    contacter = models.CharField(max_length=50, null=True, verbose_name='公安部门负责人')
    contacter_tel = models.CharField(max_length=50, null=True, verbose_name='公安部门负责人电话')
    spare = models.CharField(max_length=255, null=True,verbose_name='备用字段')

    def __str__(self):
        return self.username

    class Meta:
        managed = True
        db_table = 'tb_user'
        verbose_name = '用户'
        verbose_name_plural = '用户'


# 2
class Authorization(models.Model):
    """授权申请表"""
    ano = models.AutoField(primary_key=True, verbose_name='授权申请记录ID')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    level = models.IntegerField(null=False, verbose_name='申请权限等级')
    is_deal = models.BooleanField(default=False, verbose_name='是否处理')
    make_time = models.DateTimeField(verbose_name='申请时间')
    spare = models.CharField(max_length=255, null=True,verbose_name='备用字段')


    class Meta:
        managed = True
        db_table = 'tb_authorization'
        verbose_name = '授权申请'
        verbose_name_plural = '授权申请'


# 3
class Uav(models.Model):
    """无人机"""
    uno = models.AutoField(primary_key=True, verbose_name='无人机编号')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    serial_no = models.CharField(max_length=255, null=False, verbose_name='无人机序列号')
    buy_date = models.DateTimeField(verbose_name='购买日期')
    brand = models.CharField(max_length=255, verbose_name='品牌')
    model = models.CharField(max_length=255, verbose_name='型号')
    is_insurance = models.BooleanField(default=False, verbose_name='是否购买保险')
    spare = models.CharField(max_length=255, null=True,verbose_name='备用字段')


    class Meta:
        managed = True
        db_table = 'tb_uav'
        verbose_name = '无人机'
        verbose_name_plural = '无人机'


# 4
class Insurance(models.Model):
    """保险申请表"""
    ino = models.AutoField(primary_key=True, verbose_name='保险申请ID')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    uav = models.ForeignKey(to=Uav, on_delete=models.DO_NOTHING, db_column='suno', verbose_name='所属无人机')
    is_deal = models.BooleanField(default=False, verbose_name='是否处理')
    spare = models.CharField(max_length=255, null=True,verbose_name='备用字段')


    class Meta:
        managed = True
        db_table = 'tb_insurance'
        verbose_name = '保险申请'
        verbose_name_plural = '保险申请'


# 5
class Flight(models.Model):
    """飞行"""
    fno = models.AutoField(primary_key=True, verbose_name='飞行申请编号')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    number = models.IntegerField(verbose_name='无人机数量')
    begin_time = models.DateTimeField(verbose_name='开始飞行时间')
    end_time = models.DateTimeField(verbose_name='结束飞行时间')
    fly_type = models.CharField(max_length=255, verbose_name='飞行类型')
    operator = models.CharField(max_length=50, verbose_name='指挥员')
    ope_tel = models.CharField(max_length=50, verbose_name='联系电话')
    handle = models.IntegerField(choices=HANDLE_OPTIONS, default=0, verbose_name='批复状态')
    reply = models.CharField(max_length=255, verbose_name='批复意见',default='')
    make_time = models.DateTimeField(verbose_name='计划生成时间')
    spare = models.CharField(max_length=255, null=True,verbose_name='备用字段')


    class Meta:
        managed = True
        db_table = 'tb_flight'
        verbose_name = '飞行计划'
        verbose_name_plural = '飞行计划'









